package com.ruoyi.web.controller.market.special;

import java.util.List;
import java.util.Map;

import com.ruoyi.special.service.ISpecialCostomInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.SpecialCostomInfoProfit;
import com.ruoyi.special.service.ISpecialCostomInfoProfitService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.SpecialCostomInfoProfitWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机构收益Controller
 * 
 * @author ruoyi
 * @date 2023-03-12
 */
@Controller
@RequestMapping("/special/profit")
public class SpecialCostomInfoProfitController extends BaseController
{
    private String prefix = "special/profit";

    @Autowired
    private ISpecialCostomInfoProfitService specialCostomInfoProfitService;
    @Autowired
    private ISpecialCostomInfoService specialCostomInfoService;

    @RequiresPermissions("special:profit:view")
    @GetMapping()
    public String profit(ModelMap modelMap)
    {
        List<Map<String, Object>> ableCostomInfoMapList = specialCostomInfoService.getAbleCostomInfoMapList();
        modelMap.put("typeList", ableCostomInfoMapList);

        return prefix + "/profit";
    }

    /**
     * 查询机构收益列表
     */
    @RequiresPermissions("special:profit:view")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SpecialCostomInfoProfit specialCostomInfoProfit)
    {
        startPage();

        Map<String, Object> totalMap = specialCostomInfoProfitService.selectSpecialCostomInfoProfitTotalMap(specialCostomInfoProfit);

        List<Map<String, Object>> mapList = specialCostomInfoProfitService.selectSpecialCostomInfoProfitListMap(specialCostomInfoProfit);
        mapList = new SpecialCostomInfoProfitWapper(mapList).wrap();

        mapList.add(0, totalMap);

        return getDataTable(mapList);
    }

    /**
     * 导出机构收益列表
     */
    @RequiresPermissions("special:profit:export")
    @Log(title = "机构收益", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SpecialCostomInfoProfit specialCostomInfoProfit)
    {
        List<SpecialCostomInfoProfit> list = specialCostomInfoProfitService.selectSpecialCostomInfoProfitList(specialCostomInfoProfit);
        ExcelUtil<SpecialCostomInfoProfit> util = new ExcelUtil<SpecialCostomInfoProfit>(SpecialCostomInfoProfit.class);
        return util.exportExcel(list, "机构收益数据");
    }

    /**
     * 新增机构收益
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        List<Map<String, Object>> ableCostomInfoMapList = specialCostomInfoService.getAbleCostomInfoMapList();
        modelMap.put("typeList", ableCostomInfoMapList);

        return prefix + "/add";
    }

    /**
     * 新增保存机构收益
     */
    @RequiresPermissions("special:profit:add")
    @Log(title = "机构收益", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SpecialCostomInfoProfit specialCostomInfoProfit)
    {
        return toAjax(specialCostomInfoProfitService.insertSpecialCostomInfoProfit(specialCostomInfoProfit));
    }

    /**
     * 修改机构收益
     */
    @RequiresPermissions("special:profit:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SpecialCostomInfoProfit specialCostomInfoProfit = specialCostomInfoProfitService.selectSpecialCostomInfoProfitById(id);
        mmap.put("specialCostomInfoProfit", specialCostomInfoProfit);
        return prefix + "/edit";
    }

    /**
     * 修改保存机构收益
     */
    @RequiresPermissions("special:profit:edit")
    @Log(title = "机构收益", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SpecialCostomInfoProfit specialCostomInfoProfit)
    {
        return toAjax(specialCostomInfoProfitService.updateSpecialCostomInfoProfit(specialCostomInfoProfit));
    }

    /**
     * 删除机构收益
     */
    @RequiresPermissions("special:profit:remove")
    @Log(title = "机构收益", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(specialCostomInfoProfitService.deleteSpecialCostomInfoProfitByIds(ids));
    }
}
